//
//  SinaTabBar.swift
//  weibo
//
//  Created by liuchao on 16/1/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SinaTabBar: UITabBar {

    
    override func layoutSubviews() {
       /// print(subviews)
        
        componetButton.center=CGPointMake(bounds.width*0.5, bounds.height*0.5)
        
        var index=0
        
        let width=bounds.width/5.0
        
        
        for subview in subviews{
        
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
            
                subview.frame=CGRectMake(CGFloat(index) * width, bounds.origin.y, width, bounds.height)
                
                index++
                
                if index==2{
                  index++
                }
                
            }
            

        }
        
    }
    
    override init(frame: CGRect) {
        //初始化
        super.init(frame: frame)
        
        addSubview(componetButton)
    
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var componetButton:UIButton={
    
        let button=UIButton(type: UIButtonType.Custom)
        
        // 设置属性
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        
        return button
        
    }()
}
